﻿<div class="content-top-nav">
    <div class="layui-row">
        <div class="layui-col-md11">
            <h3 style="color:#444">
                <i class="layui-icon layui-icon-home"></i>
                消息 / 收信
            </h3>
        </div>
        <div class="layui-col-md1" style="text-align:right;">
        </div>
    </div>
    <hr>
</div>

<div class="layui-fluid" style="margin-bottom:50px;">
    <div class="layui-card">
        <form class="layui-form" action="" lay-filter="FormSearch" enctype="multipart/form-data">
            <div class="layui-card-body ">
                <div class="layui-form">
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="keyword" id="keyword" placeholder="按标题搜索" class="layui-input" style="width:320px;">
                    </div>
                    <div class="layui-inline layui-show-xs-block" style="width:80px;">
                        <select id="status" name="status" lay-verify="required">
                            <option value="">全部</option>
                            <option value="1">已读</option>
                            <option value="0">未读</option>
                        </select>
                    </div>

                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" data-type="reload" id="searchBtn"><i class="layui-icon">&#xe615;</i></button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>
        </form>

    </div>

    <script type="text/html" id="toolbarAE">
        <div><i class="layui-icon layui-icon-notice"></i> 消息，可用于文件共享，信息交流等功能！</div>
    </script>

    <table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>

    <script type="text/html" id="contentUrlTpl">
        {{# if(d.status == 1){  }}
        <div style="cursor: pointer;  color: #0d8e03" lay-event="openContent">{{d.title}}</div>
        {{# }else{ }}
        <div style="cursor: pointer; color: red" lay-event="openContent">{{d.title}}</div>
        {{# } }}
    </script>

    <script type="text/html" id="Type">
        {{# if(d.type == 1){  }}
        User
        {{# }else{ }}
        <span style="color:#FF5722">系统</span>
        {{# } }}
    </script>
    <script type="text/html" id="getTpl">
        {{d.nickname}}  ({{d.username}})
    </script>
    <script type="text/html" id="postTpl">
        {{# if(d.postUid == 0){  }}
        <span style="color:#FF5722">System</span>
        {{# }else{ }}
        {{d.postNickname}} ({{d.postname}})
        {{# } }}
    </script>
    <script type="text/html" id="Status">
        {{# if(d.status == 1){  }}
        <div style="cursor: pointer;  color: #0d8e03" lay-event="openContent">已读({{ d.readTime }}) </div>
        {{# }else{ }}
        <span style="color: #FF5722;cursor: pointer;"  lay-event="openContent">未读</span>
        {{# } }}
    </script>

    <script type="text/html" id="currentTableBar">
        @if (await Authorizer.AuthView(PermissionKeys.Notice_Delete))
        {
                        <a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</a>
        }
        else
        {
                        <a class="layui-btn layui-btn-sm layui-btn-disabled"><i class="layui-icon">&#xe640;</i>删除</a>
        }
    </script>

</div>
<script>
    layui.define(function () {
        var table = layui.table, $ = layui.jquery, form = layui.form, util = layui.util;

        form.render();

        var tableIns = table.render({
            elem: '#currentTableId',
            url: '/Admin/Notice/Index?json=1',
            toolbar: '#toolbarAE',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 1 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            cols: [[
                { field: 'id', width: 70, title: 'ID', sort: true },
                { field: 'title', title: '标题', templet: '#contentUrlTpl' },
                { field: 'type', width: 100, title: '类型', templet: '#Type' },
                { field: 'username', width: 160, title: '收件人', templet: '#getTpl' },
                { field: 'postname', width: 130, title: '发件人', templet: '#postTpl' },
                { field: 'postTime', width: 180, title: '发布时间' },
                { field: 'status', width: 200, title: '状态', templet: '#Status', sort: true },
                { title: '操作', width: 180, templet: '#currentTableBar', fixed: "right", align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            id: 'tableReload',
            page: true
        });

        //搜索重载表格
        $('#searchBtn').on('click', function () {
            tableIns.reload({
                method: 'get',
                where: {
                    keyword: $('#keyword').val(),
                    status: $('#status').val(),
                },
                page: {
                    curr: 1
                },
                page: true,
            });
            return false;
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('确定删除 名为' + data.title + '的通知吗？', {
                    btn: ['确定', '取消']
                }, function (index) {
                    $.post('/Admin/Notice/Delete?id=' + data.id, function (res) {
                        if (res.status == 1) {
                            layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                obj.del();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                        }
                    });
                });
            } else if (obj.event === 'openContent') {
                layer.open({
                    type: 2,
                    title: "信件详情",
                    area: ['800px', '500px'],
                    closeBtn: 1, //不显示关闭按钮
                    anim: 2,
                    shadeClose: true, //开启遮罩关闭
                    content: "/Admin/Notice/Read?id=" + data.id + "&noticeid=" + data.noticeId
                });
            } else {
                layer.msg("没有权限！");
            }
        });
    });


</script>
